using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Assignment2
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class FontEffects : Microsoft.Xna.Framework.DrawableGameComponent
    {

        public Vector2 fontPosition { get; set; }
        public SpriteFont fontStyle { get; set; }
        public int fontShadows { get; set; }
        public Color fontColor { get; set; }
        public Color shadowColor { get; set; }
        public string text { get; set; }
        public float fontAlpha { get; set; }
        public float shadowAlpha { get; set; }
        public float shadowDistance { get; set; }
        private Vector2 drawPosition;
        Vector2 textOrigin;    
        const float textSize = 0.2f;

        public FontEffects(Game game, Vector2 fontPosition, SpriteFont fontStyle, string text)
            : base(game)
        {
            // TODO: Construct any child components here
            StartUp(fontPosition, fontStyle, 2, Color.Black, Color.Black, .2f, 1f, 1f, text);
        }

        public FontEffects(Game game, Vector2 fontPosition, SpriteFont fontStyle, int fontShadows,
            Color fontColor, float fontAlpha, string text)
            : base(game)
        {
            // TODO: Construct any child components here
            StartUp(fontPosition, fontStyle, fontShadows, fontColor, Color.Black, .2f, fontAlpha, 1f, text);
        }

        public FontEffects(Game game, Vector2 fontPosition, SpriteFont fontStyle, int fontShadows,
            Color fontColor, Color shadowColor, float shadowDistance, float fontAlpha, float shadowAlpha, string text)
            : base(game)
        {
            // TODO: Construct any child components here
            StartUp(fontPosition, fontStyle, fontShadows, fontColor, shadowColor, shadowDistance, fontAlpha, shadowAlpha, text);
        }

        public void StartUp(Vector2 fontPosition, SpriteFont fontStyle, int fontShadows, Color fontColor,
            Color shadowColor, float shadowDistance, float fontAlpha, float shadowAlpha, string text)
        {
            this.fontPosition = fontPosition;
            this.fontStyle = fontStyle;
            this.fontShadows = fontShadows;
            this.fontColor = fontColor;
            this.shadowColor = shadowColor;
            this.shadowDistance = shadowDistance;
            this.fontAlpha = fontAlpha;
            this.shadowAlpha = shadowAlpha;
            this.text = text;
            drawPosition = fontPosition - new Vector2(fontShadows * shadowDistance, fontShadows * shadowDistance);
        }        

        public void SetFontPosition(Vector2 newPos)
        {
            fontPosition = newPos;
            drawPosition = fontPosition - new Vector2(fontShadows * shadowDistance, fontShadows * shadowDistance);
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        public void Draw(GameTime gameTime, SpriteBatch sb)
        {            
            textOrigin = fontStyle.MeasureString(text) / 2;
            for (int i = 0; i < fontShadows - 1; i++)
                sb.DrawString(fontStyle, text, drawPosition + new Vector2(shadowDistance * i, shadowDistance * i), shadowColor * shadowAlpha, 0, textOrigin, textSize, 0, 0);                        
            sb.DrawString(fontStyle, text, fontPosition, fontColor * fontAlpha, 0, textOrigin, textSize, 0, 0);            
            
            base.Draw(gameTime);
        }
    }
}
